import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useJobsStore = defineStore('jobs', () => {
  const jobs = ref([])
  const currentJob = ref(null)
  const customerRegistrations = ref([])

  function setJobs(jobsList) {
    jobs.value = jobsList
  }

  function setCurrentJob(job) {
    currentJob.value = job
  }

  function addCustomerRegistration(registration) {
    customerRegistrations.value.push(registration)
  }

  function getCustomerRegistrationsByUserId(userId) {
    return customerRegistrations.value.filter(reg => reg.shareUserId === userId)
  }

  function getCustomerRegistrationsByJobId(jobId) {
    return customerRegistrations.value.filter(reg => reg.jobId === jobId)
  }

  return {
    jobs,
    currentJob,
    customerRegistrations,
    setJobs,
    setCurrentJob,
    addCustomerRegistration,
    getCustomerRegistrationsByUserId,
    getCustomerRegistrationsByJobId
  }
}) 